namespace QMVnSoft.Controls
{
    using QMVnSoft;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormHistoryFilter : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnOk;
        private CBoxControl cBoxDmCt;
        private IContainer components;
        private GBoxControl gBoxControl1;
        private bool ib_CheckAccepted;
        private string is_InvoiceCode = "";
        private LabelControl lblNgay_Ct1;
        private LabelControl lblNgay_Ct2;
        private TextDate txtNgay_Ct1;
        private TextDate txtNgay_Ct2;

        public FormHistoryFilter()
        {
            this.InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.CheckAccepted = true;
            base.Close();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FillInvoices(string ps_InvoiceCode)
        {
            DataTable invoices = new AppInvoiceLibDataAccess().GetInvoices(ps_InvoiceCode);
            this.cBoxDmCt.DataSource = invoices;
            this.cBoxDmCt.DisplayMember = "Ten_Ct";
            this.cBoxDmCt.ValueMember = "Ma_Ct";
            if (!string.IsNullOrEmpty(ps_InvoiceCode))
            {
                this.cBoxDmCt.SelectedValue = ps_InvoiceCode;
            }
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormHistoryFilter));
            this.txtNgay_Ct2 = new QMVnSoft.Controls.TextDate();
            this.lblNgay_Ct2 = new QMVnSoft.Controls.LabelControl();
            this.txtNgay_Ct1 = new QMVnSoft.Controls.TextDate();
            this.lblNgay_Ct1 = new QMVnSoft.Controls.LabelControl();
            this.btnCancel = new QMVnSoft.Controls.BtnControl();
            this.btnOk = new QMVnSoft.Controls.BtnControl();
            this.gBoxControl1 = new QMVnSoft.Controls.GBoxControl();
            this.cBoxDmCt = new QMVnSoft.Controls.CBoxControl();
            this.SuspendLayout();
            // 
            // txtNgay_Ct2
            // 
            this.txtNgay_Ct2.DateTimeFormat  = QMVnSoft.Controls.TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ct2.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtNgay_Ct2.InsertKeyMode = System.Windows.Forms.InsertKeyMode.Overwrite;
            this.txtNgay_Ct2.Location = new System.Drawing.Point(162, 92);
            this.txtNgay_Ct2.Mask = "00/00/0000";
            this.txtNgay_Ct2.Name = "txtNgay_Ct2";
            this.txtNgay_Ct2.OldValue = null;
            this.txtNgay_Ct2.Size = new System.Drawing.Size(100, 20);
            this.txtNgay_Ct2.TabIndex = 2;
            this.txtNgay_Ct2.Value = ((object)(resources.GetObject("txtNgay_Ct2.Value")));
            // 
            // lblNgay_Ct2
            // 
            this.lblNgay_Ct2.AutoSize = true;
            this.lblNgay_Ct2.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblNgay_Ct2.Location = new System.Drawing.Point(66, 95);
            this.lblNgay_Ct2.Name = "lblNgay_Ct2";
            this.lblNgay_Ct2.Size = new System.Drawing.Size(54, 14);
            this.lblNgay_Ct2.TabIndex = 4;
            this.lblNgay_Ct2.Text = "Đến ngày";
            // 
            // txtNgay_Ct1
            // 
            this.txtNgay_Ct1.DateTimeFormat  = QMVnSoft.Controls.TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ct1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtNgay_Ct1.InsertKeyMode = System.Windows.Forms.InsertKeyMode.Overwrite;
            this.txtNgay_Ct1.Location = new System.Drawing.Point(162, 66);
            this.txtNgay_Ct1.Mask = "00/00/0000";
            this.txtNgay_Ct1.Name = "txtNgay_Ct1";
            this.txtNgay_Ct1.OldValue = null;
            this.txtNgay_Ct1.Size = new System.Drawing.Size(100, 20);
            this.txtNgay_Ct1.TabIndex = 1;
            this.txtNgay_Ct1.Value = ((object)(resources.GetObject("txtNgay_Ct1.Value")));
            // 
            // lblNgay_Ct1
            // 
            this.lblNgay_Ct1.AutoSize = true;
            this.lblNgay_Ct1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblNgay_Ct1.Location = new System.Drawing.Point(66, 69);
            this.lblNgay_Ct1.Name = "lblNgay_Ct1";
            this.lblNgay_Ct1.Size = new System.Drawing.Size(47, 14);
            this.lblNgay_Ct1.TabIndex = 3;
            this.lblNgay_Ct1.Text = "Từ ngày";
            // 
            // btnCancel
            // 
            this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnCancel.Location = new System.Drawing.Point(262, 147);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(94, 23);
            this.btnCancel.TabIndex = 4;
            this.btnCancel.Text = "&Huỷ bỏ";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // btnOk
            // 
            this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnOk.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnOk.Location = new System.Drawing.Point(162, 147);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new System.Drawing.Size(94, 23);
            this.btnOk.TabIndex = 3;
            this.btnOk.Text = "&Chấp nhận";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
            // 
            // gBoxControl1
            // 
            this.gBoxControl1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.gBoxControl1.Location = new System.Drawing.Point(12, 42);
            this.gBoxControl1.Name = "gBoxControl1";
            this.gBoxControl1.Size = new System.Drawing.Size(344, 89);
            this.gBoxControl1.TabIndex = 5;
            this.gBoxControl1.TabStop = false;
            // 
            // cBoxDmCt
            // 
            this.cBoxDmCt.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cBoxDmCt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.cBoxDmCt.FormattingEnabled = true;
            this.cBoxDmCt.Location = new System.Drawing.Point(12, 12);
            this.cBoxDmCt.Name = "cBoxDmCt";
            this.cBoxDmCt.Size = new System.Drawing.Size(344, 22);
            this.cBoxDmCt.TabIndex = 0;
            // 
            // FormHistoryFilter
            // 
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(368, 182);
            this.Controls.Add(this.cBoxDmCt);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnOk);
            this.Controls.Add(this.txtNgay_Ct2);
            this.Controls.Add(this.lblNgay_Ct2);
            this.Controls.Add(this.txtNgay_Ct1);
            this.Controls.Add(this.lblNgay_Ct1);
            this.Controls.Add(this.gBoxControl1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FormHistoryFilter";
            this.Text = "Điều kiện lọc";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Return))
            {
                this.CheckAccepted = true;
                base.Close();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        public bool CheckAccepted
        {
            get
            {
                return this.ib_CheckAccepted;
            }
            set
            {
                this.ib_CheckAccepted = value;
            }
        }

        public string InvoiceCode
        {
            get
            {
                if ((this.cBoxDmCt != null) && (this.cBoxDmCt.Items.Count > 0))
                {
                    return this.cBoxDmCt.SelectedValue.ToString();
                }
                return "";
            }
            set
            {
                this.is_InvoiceCode = value;
                this.FillInvoices(this.is_InvoiceCode);
            }
        }

        public object Ngay_Ct1
        {
            get
            {
                if (this.txtNgay_Ct1.Value != DBNull.Value)
                {
                    AppInstance.StartWorkingDate = (DateTime) this.txtNgay_Ct1.Value;
                    return AppInstance.StartWorkingDate;
                }
                return DBNull.Value;
            }
            set
            {
                if ((value == DBNull.Value) || (value == null))
                {
                    value = AppInstance.StartWorkingDate;
                }
                this.txtNgay_Ct1.Value = value;
            }
        }

        public object Ngay_Ct2
        {
            get
            {
                if (this.txtNgay_Ct2.Value != DBNull.Value)
                {
                    AppInstance.EndWorkingDate = (DateTime) this.txtNgay_Ct2.Value;
                    return AppInstance.EndWorkingDate;
                }
                return DBNull.Value;
            }
            set
            {
                if ((value == DBNull.Value) || (value == null))
                {
                    value = AppInstance.EndWorkingDate;
                }
                this.txtNgay_Ct2.Value = value;
            }
        }


    }
}

